package com.czy.fx.day1.input;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class demo2 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("标题");
        primaryStage.setWidth(800);
        primaryStage.setHeight(800);
        Group group = new Group();
        primaryStage.setScene(new Scene(group));

        //密码输入框
        TextField text = new PasswordField();
        group.getChildren().add(text);
        
        //text.setText("文本框");
        text.setLayoutX(100);
        text.setLayoutY(100);
        text.setPrefWidth(150);
        text.setPrefHeight(50);
        text.setStyle("-fx-background-color: #1169EE20;"+ //背景颜色
                "-fx-text-fill: #1f1c1c;"+ //文本颜色
                "-fx-border-color: #EE1169;"+ //边框颜色
                "-fx-border-radius: 5;"+ //边框圆角
                "-fx-background-radius: 5;"+ //背景圆角
                "-fx-background-insets: 5;"+ //边框到背景的距离
                "-fx-font-size: 15;"+ //字体大小
                "-fx-font-family: '宋体';"+ //字体
                "-fx-border-style: dotted;"+ //边框样式
                "-fx-border-width: 0;" //边框宽度
        );
        /*鼠标放入 提示框*/
        Tooltip tooltip = new Tooltip("提示");
        tooltip.setFont(Font.font(20));
        text.setTooltip(tooltip);
        text.setFocusTraversable(false);
        text.setPromptText("限制输入7位字符");
        text.textProperty().addListener((observable, oldValue, newValue) -> {
            System.out.println(newValue);
            if (newValue.length() > 7) {
                text.setText(oldValue);
            }
        });


        primaryStage.show();
    }
}
